'''
Description: 
Autor: didiplus
Date: 2023-01-13 14:22:38
LastEditors: lin
LastEditTime: 2023-01-13 14:41:15
'''
from fastapi import FastAPI
import time
from concurrent.futures import ThreadPoolExecutor


app = FastAPI()
pool = ThreadPoolExecutor()

def read_file():
    time.sleep(0.1)
    return "result_file"

def read_db():
    time.sleep(0.2)
    return "read_db"

def read_api():
    time.sleep(0.3)
    return "read_api"

@app.get("/")
def index():
    result_file  = pool.submit(read_file)
    result_db  = pool.submit(read_db)
    result_api  = pool.submit(read_api)
    return {
        "result_file":result_file.result(),
        "read_db":result_db.result(),
        "read_api":result_api.result()
        }
    # return {
    #     "result_file":read_file(),
    #     "read_db":read_db(),
    #     "read_api":read_api()
    #     }


if __name__  == "__main__":
    import uvicorn
    uvicorn.run(app)
